package org.example.com.Test;

import jakarta.annotation.Resource;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.example.com.Bean.Book;
import org.example.com.Bean.Category;
import org.example.com.Bean.User;
import org.example.com.service.BookService;
import org.example.com.service.CategoryService;
import org.example.com.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.security.NoSuchAlgorithmException;
import java.util.List;
@SpringBootTest
@Slf4j
public class App {
    @Resource
    private BookService bookService;
    @Test
    public void find(){
        List<Book> list = bookService.list();
        list.forEach(book -> {
            log.info("book:{}", book);
        });
    }
    @Resource
    private CategoryService categoryService;
    @Test
    public void findCategory(){
        List<Category> list = categoryService.list();
        list.forEach(category -> {
            log.info("category:{}", category);
        });
    }
    @Resource
    private UserService userService;
    @Test
    public void findUser(){
        List<User> list=userService.list();
        list.forEach(user -> {
            log.info("user:{}",user);
        });
    }
    @Test
    public void insertBook(){
        Book book = new Book();
        book.setId("1521453234873850200");
        book.setCategoryId("1521444078676357121");
        book.setName("存在即合理");
        book.setAuthor("达尔文");
        book.setPublisher("商务印书馆");
        book.setPrice("33.9");
        book.setImageName("http://localhost:8000/images/52513726-760c-4999-ad6f-cccd600df6b4.png");
        book.setDescription("历经几次修改完善，当代著名哲学家陈嘉映、王庆节精心打磨。哲学家海德格尔代表作、成名作。基本思想——存在就是时间，此书的主要任务在于追问并解答两千年西方哲学史上遗忘了的根本问题——“存在”问题。");
        book.setCreateTime("2022-05-07 10:35:33");
        book.setUpdateTime("2024-05-07 10:35:33");
        book.setStatus("1");
        book.setIsDeleted("0");
        book.setImageState("1");
        bookService.save(book);
    }
    @Test
    public void deleteBook(){
        bookService.removeById("1521453234873850200");
    }
    @Test
    public void updateBook(){
        Book book = new Book();
        book.setPrice("99.9");
       book.setAuthor("lllllll");
       book.setId("1521453234873850199");
        bookService.updateById(book);
    }
    @SneakyThrows
    @Test
    public void insertUser(){
        User user = new User();
        user.setId("1827954179468574722");
        user.setUsername("aaaaaaa");
        user.setPassword("99999");
        user.setPhone("18998775644");
        user.setEmail("aaaaaa@qq.com");
        user.setAddress("xx省xx市");
        user.setStatus(1);
        user.setCreateTime("2022-05-03 09:05:37");
        user.setUpdateTime("2024-06-03 09:05:37");
        user.setIsDeleted(0);
        user.setIsAdmin(0);
        user.setScore(0);
        userService.save(user);
    }
    @Test
    public void deleteUser(){
        userService.removeById("1827954179468574722");
    }
    @Test
    public void updateUser() throws NoSuchAlgorithmException {
        User user = new User();
        user.setId("1787729479350251522");
        user.setUsername("aaaaaaa");
        user.setPassword("99999");
        userService.updateById(user);
    }
    @Test
    public void insertCategory(){
        Category category = new Category();
        category.setId("1530028772720394242");
        category.setName("数学类");
        category.setSort(13);
        category.setStatus(1);
        category.setCreateTime("2022-05-03 09:05:37");
        category.setUpdateTime("2024-06-03 09:05:37");
        category.setIsDeleted(0);
        categoryService.save(category);
    }
    @Test
    public void deleteCategory(){
        categoryService.removeById("1530028772720394242");
    }
    @Test
    public void updateCategory(){
        Category category = new Category();
        category.setId("1530028772720394241");
        category.setSort(23);
        category.setCreateTime("2022-01-03 09:05:37");
        category.setUpdateTime("2024-02-03 09:05:37");
        categoryService.updateById(category);
    }
}
